/**
 * 删除名片或取消收藏名名用户
 * 详情页
 * 列表页
 */
import wepy from 'wepy';
import tip from '@/utils/tip';
import api from '@/api/api';
export default class CancelOrDel extends wepy.mixin {
  methods = {
    async cancelOrDel(type, id, uid, collectState) {
      //取消/添加收藏 接口参数
      try {
        let rlt;
        if (+type === 1) {
          await tip.confirm('确认对此名片取消收藏？');
          rlt = await api.collAddOrEdit({
            query: {
              cardId: id,
              collection_uid: uid,
              is_delete: collectState
            }
          });
        } else {
          await tip.confirm('确认删除该名片？');
          rlt = await api.cardDelete({
            query: {
              id: id
            }
          });
        }

        if (+rlt.data.code === 12000) {
          await tip.success('删除成功', 1000);

          wepy.switchTab({
            url: './card'
          });

          this.$invoke('../', 'getCardcase');

        }
      } catch (err) {
        console.log(err);
      }
    }
  }
}